package com.example.demo.common;

import lombok.Data;

/**
 * @author KUBUB
 */
@Data
public class BaseException extends RuntimeException{
    /**
     * 序列化
     */
    private static final long serialVersionUID = -8329283070529101738L;

    /**
     * 错误码
     */
    protected String code;

    /**
     * 错误信息
     */
    protected String message;

    /**
     * 默认构造方法
     */
    public BaseException(){
        super();
    }

    /**
     * 默认构造方法
     * @param errorInfoInterface
     */
    public BaseException(BaseErrorInfoInterface errorInfoInterface){
        super(errorInfoInterface.getResultCode());
        this.code = errorInfoInterface.getResultCode();
        this.message = errorInfoInterface.getResultMsg();
    }

    /**
     * 默认构造方法
     * @param errorInfoInterface
     *              错误返回码
     * @param cause
     *              Throwable
     */
    public BaseException(BaseErrorInfoInterface errorInfoInterface,Throwable cause){
        super(errorInfoInterface.getResultCode(),cause);
        this.code = errorInfoInterface.getResultCode();
        this.message = errorInfoInterface.getResultMsg();
    }

    /**
     * 默认构造方法
     * @param errorMsg
     *              错误信息
     */
    public BaseException(String errorMsg){
        super(errorMsg);
        this.message = errorMsg;
    }

    /**
     * 默认构造方法
     * @param errorCode
     *              错误码
     * @param errorMsg
     *              错误信息
     */
    public BaseException(String errorCode,String errorMsg){
        super(errorCode);
        this.code = errorCode;
        this.message = errorMsg;
    }

    /**
     * 默认构造方法
     * @param errorCode
     *              错误码
     * @param errorMsg
     *              错误信息
     * @param cause
     *              Throwable
     */
    public BaseException(String errorCode,String errorMsg,Throwable cause){
        super(errorCode,cause);
        this.code = errorCode;
        this.message = errorMsg;
    }

    @Override
    public synchronized Throwable fillInStackTrace() {
        return this;
    }
}
